<template>
    <div>
        <img class="login_img" src="../../assets/img/login.jpg" alt="">
    </div>
    <van-form @submit="onSubmit">
        <van-cell-group inset>
            <van-field v-model="phone" name="phone" label="手机号码" placeholder="请输入手机号码"
                :rules="[{ required: true, message: '请填写用户名' }]" />
            <van-field v-model="password" type="password" name="password" label="登录密码" placeholder="请输入登录密码"
                :rules="[{ required: true, message: '请填写密码' }]" />
        </van-cell-group>
        <div style="margin: 16px;">
            <van-button round block type="primary" native-type="submit">
                登录
            </van-button>
        </div>
    </van-form>
    <div class="login_btn">
        <router-link class="btn" to="/resetPwd">忘记密码？</router-link>
        <router-link class="btn" to="/register">注册账号</router-link>
    </div>
    <div class="login_copyright">
        <span>千锋教育@2023-2026</span>
    </div>
</template>
<script>
import axios from 'axios'
export default {
    data() {
        return {
            phone:'17858984792',
            password:'123456'
        }
    },
    methods:{
        onSubmit(){
            axios.post('http://localhost:6001/login',{
                phone:this.phone,
                password:this.password
            }).then(res=>{
                const data = res.data
                if(!data.success){
                    return alert(data.message)
                }
                localStorage.userId = data.result._id
                this.$store.commit('setPersonal',data.result)
                this.$router.push('/')

            })
        }
    },
    create(){
       this.phone = this.$route.query.phone 
    }
}
</script>

<style scoped>
.login_img {
    width: 100%;
    margin-bottom: 50px;
}

.login_copyright {
    position: absolute;
    bottom: 50px;
    display: flex;
    width: 100%;
    justify-content: center;
    color: #aaa;
    font-size: 12px;
}
.login_btn {
    margin-top: 30px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    /* background-color: red; */

}
.btn{
    font-size: 12px;
    text-align: center;
    width: 100px;
    margin: 0px 20px;
    
}
</style>